

import { Controller } from 'egg';

export default class UserController extends Controller {
    public async index() {
        const { ctx } = this;
        ctx.body = await ctx.service.test.sayHi('egg');
    }

    public async detail() {
        const id = this.ctx.params.id;
        const url = `/weapi/v1/user/detail/${id}`;
        const data = {
            csrf_token: ""
        };

        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        const { body, cookie } = result;

        cookie && this.service.mequest.parseCookie(cookie).forEach(ck => {

            this.ctx.cookies.set(ck.cookie.name, ck.cookie.value, ck.options)
        })
        this.ctx.body = body;
    }
    // 获取  获取用户信息 , 歌单，收藏，mv, dj 数量  /user/subcount
    public async subcount() {
        const url = `/weapi/subcount`;
        const data = {
            csrf_token: ""
        };

        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        const { body, cookie } = result;

        cookie && this.service.mequest.parseCookie(cookie).forEach(ck => {

            this.ctx.cookies.set(ck.cookie.name, ck.cookie.value, ck.options)
        })
        this.ctx.body = body;
    }

    public async playlist() {
        const { id, offset, limit } = this.ctx.query;
        const url = `/weapi/user/playlist`;
        const data = {
            offset: offset || 0,
            uid: id,
            limit: limit || 30, //貌似无效
            csrf_token: ""
        }

        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        const { body, cookie } = result;

        cookie && this.service.mequest.parseCookie(cookie).forEach(ck => {

            this.ctx.cookies.set(ck.cookie.name, ck.cookie.value, ck.options)
        })
        this.ctx.body = body;
    }

    /**
     * dj
     */
    public async dj() {
        const { id, offset, limit } = this.ctx.query;

        const data = {
            offset: offset || "0",
            limit: limit || 30,
            csrf_token: ""
        };
        const url = `/weapi/dj/program/${id}`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        const { body, cookie } = result;

        cookie && this.service.mequest.parseCookie(cookie).forEach(ck => {
            this.ctx.cookies.set(ck.cookie.name, ck.cookie.value, ck.options)
        })
        console.log('artist body',body)
        this.ctx.body = body;
    }

    

}



// 13204652